﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
    using DAL.Entities;

    public class DonvitinhDAL : BaseDAL, UTL.IBaseDAL 
    {
        public int Count()
        {
            throw new NotImplementedException();
        }

        public DataTable Select()
        {
            string sql = @" SELECT * FROM donvitinh";
            return ExecuteQuery(sql);
        }

        public DataTable Select(object obj)
        {
            throw new NotImplementedException();
        }

        public object GetByKey(object key)
        {
            throw new NotImplementedException();
        }

        public bool Delete(string id)
        {
            string sql = @"DELETE FROM donvitinh WHERE madvt = '{0}'";
            sql = string.Format(sql,id);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Insert(object obj)
        {
            var o = (donvitinh)obj;
            string sql = @"INSERT INTO donvitinh(madvt,denvitinh) VALUES('{0}',N'{1}')";
            sql = string.Format(sql,o.madvt,o.denvi_tinh);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Update(object obj)
        {
            var o = (donvitinh)obj;
            string sql = @"UPDATE donvitinh SET denvitinh=N'{0}' where madvt='{1}'";
            sql = string.Format(sql,o.denvi_tinh,o.madvt);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public DataTable Search(string name)
        {
            throw new NotImplementedException();
        }

        public DataTable Select_max()
        {
            string sql = @"SELECT max(madvt) as id FROM donvitinh";
            return ExecuteQuery(sql);
        }



        public bool deleteobj(object obj)
        {
            throw new NotImplementedException();
        }
    }
}
